package com.bys.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bys.entity.User;
import com.bys.mapper.UserMapper;
import com.bys.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bys.vo.UserVo;
import org.example.util.PageResult;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bys
 * @since 2025-01-07
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public PageResult<User> findByPage(Integer page, Integer pageSize) {
        Page<User> page1 = this.page(new Page<>(page, pageSize));
        return new PageResult<>(page1.getRecords(),page1.getTotal());
    }

    @Override
    public PageResult<User> search(Integer page, Integer pageSize, UserVo vo) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(vo.getName()), "name", vo.getName());
        wrapper.eq(vo.getSex() != null, "sex", vo.getSex());
        Page<User> page1 = this.page(new Page<>(page, pageSize), wrapper);
        return new PageResult<>(page1.getRecords(),page1.getTotal());
    }
}
